// pages/home/registered/registered.js
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    trigger: true,
    myresume: {
      identityStatu: true,
      identity: '',
      name: '',
      gender: '',
      age: '',
      phone: '',
      email: '',
      address: '',
      company: '',
      prefer: [],
      experience: '',
      selfReview: ''
    }
  },


  changeTrigger: function (e) {
    var errorMsg
    var isError = true
    console.log(e.detail)
    if (e.detail.name == '') {
      errorMsg = "未输入姓名"
    } else if (e.detail.gender == '') {
      errorMsg = "未选择性别"
    } else if (e.detail.age == '') {
      errorMsg = "未选择年龄"
    } else if (e.detail.phone == '') {
      errorMsg = "未选择手机号"
    } else if (e.detail.identity == '') {
      errorMsg = "未选择身份"
    } else {
      isError = false
    }

    if (isError) {
      wx.showToast({
        title: errorMsg,
        icon: 'error',
        duration: 2000
      })
    } else {
      var tableName
      var identityStatu 

      if (e.detail.identityStatu) {
        tableName = "usersData"
        identityStatu = 1
      } else {
        tableName = "shopmanData"
        identityStatu = 2
      }

      db.collection(tableName).add({
        data: {
          name: e.detail.name,
          gender: e.detail.gender,
          age: e.detail.age,
          phone: e.detail.phone,
          email: e.detail.email,
          address: e.detail.address,
          prefer: e.detail.prefer,
          experience: e.detail.experience,
          selfReview: e.detail.selfReview
        },
        success: res => {
          console.log("success: "+res)
          wx.setStorageSync('identityStatu', identityStatu)
          wx.switchTab({
            url: '../index/index'
          })
        },
        error: res => {
          console.log("error: "+res)
        },
      })
    }
  },
})